<!--
 * @Description: In User Settings Edit
 * @Author: your name
 * @Date: 2019-10-15 08:50:22
 * @LastEditTime: 2020-04-17 20:14:31
 * @LastEditors: Please set LastEditors
 -->

<style scoped>
    .headerBtn{
        text-align: left;
        margin: 10px;
        height: 32px;
        position: relative;
    }
    .pageStyle{
        text-align:right;
        position: relative;
        bottom: 32px;
    }
</style>
 <style >
    .ivu-table-tip{
        overflow: hidden !important;
    }
    .operation .ivu-select-arrow{
        right: 2px
    }
    .operation .ivu-select-selection{
        border-radius: 0px 4px 4px 0px
    }
    .ivu-table-wrapper{
        overflow: visible !important
    }
    .ivu-tag-border.ivu-tag-closable .ivu-icon-ios-close{
        margin-left: 0px !important
    }
    #accessPanel .ivu-modal-body{
        padding: 2px !important;
        padding-top: 0px !important;
    }
    #accessPanel .ivu-modal-header{
        padding: 2px;
    }
    #accessPanel .ivu-icon-ios-close{
        top: -2px !important;
    }
    .cccccfff .ivu-poptip-rel .ivu-tag-text{
        max-width:226px;
        white-space: nowrap;
        text-overflow: ellipsis;
        overflow: hidden;
        word-break: break-all;
        float: left;
        padding-right: 5px;
    }
    .cccccfff .ivu-tag-border.ivu-tag-closable .ivu-icon-ios-close{
        margin-left: 0px !important
    }
    </style>
    
    <template>
        <div>
            <div class="headerBtn">
                <Button type="primary" style="visibility:hidden" ><Icon type="md-add-circle" :size="16" class="position_i"/></Button>
                <Page :total="userTotal"  show-sizer :current="userCurrentPage" :page-size="usreItemPage" show-elevator :show-total= true   class-name="pageStyle" @on-change="switchineUserCurrentPage" @on-page-size-change="switchUserItemPage"/>
            </div>
            <!-- :height="tableHeight" -->
            <Table border ref="selection" :columns="userColumnsData" :data="userListData"  :stripe="true" :show-header="true"  ></Table>
            <!-- 接入虚拟机穿梭框 -->
            <Modal
                v-model="userTransfer"
                :title="userName"
                ok-canel = "关闭"
                ok-text = "接入"
                width="727"
                :loading = "userTransferLoading"
                @on-cancel="cancel"
                @on-ok="accessVm"
                >
                <RadioGroup v-model="selectDeviceType" style="float:left" @on-change="listenDeviceChange">
                    <Radio label="vmDevice">虚拟机设备</Radio>
                </RadioGroup>
                <div style="float:right;margin-left:10px;margin-right:8px">
                    <Label>允许接入：</Label>
                    <i-switch size="large" @on-change="switchAccess" v-model="accessStart">
                        <span slot="open">是</span>
                        <span slot="close">否</span>
                    </i-switch>
                </div>
                <div style="float:right;margin-right:22px;">
                    <Label>录屏设置：</Label>
                    <i-switch size="large" @on-change="switchVoid" v-model="switch1">
                        <span slot="open">开启</span>
                        <span slot="close">关闭</span>
                    </i-switch>
                </div>
                <div style="clear:both;"></div>
                <Transfer
                    :data="vmGroupData"
                    :target-keys="userGroupDataTargetData"
                    :selected-keys="userGroupDataTargetDataSelect"
                    :render-format="rednerItemUserData"
                    :filter-method="reachTextLabel"
                    :operations="['删除','添加']"
                    :list-style="listStyle"
                    :titles="['所有设备','已选设备']"
                    filterable
                    @on-change="listenChangeData"></Transfer>
            </Modal>
            <!-- 剔除虚拟机穿梭框 -->
            <Modal
                v-model="userTransferDelete"
                title="剔除虚拟机"
                ok-canel = "关闭"
                width="727"
                ok-text = "剔除"
                :loading = "userTransferDeleteLoading"
                @on-cancel="cancel"
                @on-ok="deleteVm"
                >
                <Tag type="dot"  color="primary" >用户：{{userName}}</Tag>
                <Transfer
                    :data="accessVmGroup"
                    :target-keys="userGroupDataTargetData"
                    :render-format="rednerItemUserData"
                    :filter-method="reachTextLabel"
                    :operations="['删除','添加']"
                    :list-style="listStyle"
                    :titles="['已接入设备','剔除设备']"
                    filterable
                    @on-change="listenChangeData"></Transfer>
            </Modal>
            
        </div>
    </template>
    <script src="../../../../static/all.min.js"></script>
    <script>
    import axios from '@/libs/axios1'
    import $ from 'jquery'
    export default {
        name:'userVm',
        // props: ['headerData','sceneId'],
        components:{
            // accessuser
        },
        data(){
            return{
                accessStart:true,
                switch1:false,
                currentProjectId:'',
                userTransferLoading :true,
                userTotal:0,
                userCurrentPage:1,
                usreItemPage:10,
                userColumnsData:[
                    {
                        type: 'index',
                        width: 60,
                        align: 'center'
                    },
                    {
                        title:'名称',
                        key:'userName',
                        align:'center'
                    },
                    {
                        title:'接入组',
                        key:'accessGroupName',
                        align:'center'
                    },
                    {
                        title:'邀请人',
                        key:'inviterName',
                        align:'center'
                    },
                    {
                        title:'创建时间',
                        key:'created',
                        align:'center'
                    },
                    {
                        title:'正在接入设备',
                        key:'',
                        minWidth:80,
                        align:'center',
                        render:(h,params)=>{
                            let _this = this;
                            params = params.row;
                            if(!params.deviceList){
                                return;
                            }
                            let groupVm = params.deviceList;
                            let _arr = []
                            if(groupVm.length!=0){
                                _arr = groupVm.map((item,key)=>{
                                    if(!item.active){
                                        return;
                                    }
                                    let vodieStyle = "inline-block"
                                     return h('Poptip',{
                                            props:{
                                                confirm:true,
                                                title:"您确定要将此虚拟机剔除吗？",
                                                'v-model':'visible'
                                            },
                                            class:['ccccc'],
                                            on:{
                                                'on-ok':()=>{
                                                    _this.deleteVmFromUser(params.userId,groupVm,item.deviceId)
                                                },
                                                'on-cancel':()=>{
                                                    
                                                }
                                            }
                                        },[h('Tag',{
                                                props:{
                                                    color:"primary",
                                                    closable:false,
                                                    type:"border",
                                                    name:item.deviceId+','+params.userId
                                                },
                                                on:{
                                                    click(){
                                                        
                                                    }
                                                }
                                            },[h('Icon',{
                                                props:{
                                                    type:'md-laptop'
                                                },
                                                style:{
                                                    fontSize:'16px',
                                                    position:'relative',
                                                    top:'-2px',
                                                    left:'-5px'
                                                },
                                                on:{
                                                    click(){
                                                        
                                                    }
                                                }
                                        },''),h('span',{on:{click(){
                                                _this.$refs.accessUserId.taskDeailModal = true;
                                                _this.$refs.accessUserId.taskDeailData = [item];
                                        }}},item.deviceName),h('Icon',{
                                                props:{
                                                    type:'md-eye'
                                                },
                                                style:{
                                                    fontSize:'16px',
                                                    position:'relative',
                                                    top:'-2px',
                                                    left:'5px',
                                                    display:vodieStyle
                                                },
                                                on:{
                                                    click(){
                                                        _this.getAccessDataMethods(params.userId,item.deviceId);
                                                    }
                                                }
                                        },'')]),h('Button',{style:{display:'none'},on:{click(){}},class:[key+'-'+item.deviceId+'-'+params.userId]},'dddd')])
                                })
                            }
                            return h('div',{style:{textAlign:'left'}},_arr)
                        }
                    },
                    {
                        title:'已分配设备',
                        key:'',
                        width:300,
                        align:'center',
                        render:(h,params)=>{
                            let _this = this;
                            params = params.row;
                            if(!params.deviceList){
                                return;
                            }
                            let groupVm = params.deviceList;
                            let _arr = []
                            if(groupVm.length!=0){
                                _arr = groupVm.map((item,key)=>{
                                    let vodieStyle = "none"
                                    let accessStyle = "none";
                                    if(item.enableRecordScreen){
                                        vodieStyle = "inline-block"
                                    }else{
                                        vodieStyle = "none"
                                    }
                                    if(item.enabled){
                                        accessStyle = "inline-block"
                                    }else{
                                        accessStyle = "none"
                                    }
                                    let deviceName = item.deviceName.indexOf("：")>-1?item.deviceName:_this.getDeviceNameById(item.deviceId)||item.deviceName;
                                    deviceName = deviceName.length>30?deviceName:deviceName;
                                     return h('Poptip',{
                                            props:{
                                                confirm:true,
                                                title:"您确定要将此虚拟机剔除吗？",
                                                'v-model':'visible'
                                            },
                                            class:['cccccfff'],
                                            on:{
                                                'on-ok':()=>{
                                                    console.log(_this.userIdAndGroipId)
                                                    _this.currentAccessGroupId = params.accessGroupId;
                                                    _this.deleteVmFromUser(params.userId,groupVm,item.deviceId)
                                                },
                                                'on-cancel':()=>{
                                                    
                                                }
                                            }
                                        },[h('Tag',{
                                                props:{
                                                    color:"primary",
                                                    closable:true,
                                                    type:"border",
                                                    name:item.deviceId+','+params.userId
                                                },
                                                on:{
                                                    'on-close':function(value,name){
                                                        $('.'+key+'-'+item.deviceId+'-'+params.userId).click()
                                                        _this.userIdAndGroipId =name;
                                                    }
                                                }
                                            },[h('Icon',{
                                                props:{
                                                    type:'md-laptop'
                                                },
                                                style:{
                                                    fontSize:'16px',
                                                    position:'relative',
                                                }
                                        },''),deviceName,h('Icon',{
                                                props:{
                                                    type:'ios-videocam'
                                                },
                                                style:{
                                                    fontSize:'16px',
                                                    position:'relative',
                                                    display:vodieStyle
                                                }
                                        },''),h('Icon',{
                                                props:{
                                                    type:'md-arrow-dropright-circle'
                                                },
                                                style:{
                                                    fontSize:'16px',
                                                    position:'relative',
                                                    display:accessStyle
                                                }
                                        },'')]),h('Button',{style:{display:'none'},on:{click(){}},class:[key+'-'+item.deviceId+'-'+params.userId]},'dddd')])
                                })
                            }
                            return h('div',{style:{textAlign:'left'}},_arr)
                        }
                    },
                    {
                        title:'操作',
                        key:'',
                        align:'center',
                        render:(h,params)=>{
                            let _this = this
                            params = params.row
                            return h('div',{},[h('Button',{
                                props:{
                                    type:'primary',
                                    size:'small'
                                },
                                style:{
                                    margin:'0px 5px'
                                },
                                on:{
                                    click(){
                                        _this.userTransfer = true;
                                        _this.switch1 = false
                                        _this.selectDeviceType = "vmDevice"
                                        _this.userGroupDataTargetData = []
                                        _this.userName = params.userName;
                                        _this.groupId = params.accessGroupId
                                        _this.userId = params.userId
                                        _this.currentAccessGroupId = params.accessGroupId;
                                        _this.currentUserPartyValue  = params.partyId;
                                        _this.vmGroupData.forEach(element=>{
                                            element.disabled = false
                                        });
                                        _this.currentUserData = params.deviceList;
                                        _this.accessVmsGroup = params.deviceList;
                                        console.log(params.deviceList)
                                        _this.accessDeviceGroup = params.deviceList.map((item)=>{
                                            return item;
                                        });
                                        _this.getVmList(params.deviceList);
                                    }
                                }
                            },'接入'),h('Button',{
                                props:{
                                    type:'error',
                                    size:'small'
                                },
                                style:{
                                    margin:'0px 5px'
                                },
                                on:{
                                    click(){
                                        _this.userTransferDelete = true;
                                        _this.userGroupDataTargetData = [];
                                        _this.userName = params.userName;
                                        _this.userId = params.userId;
                                        _this.currentUserData = params.deviceList;
                                        _this.currentUserGroupId = params.accessGroupId;
                                        _this.currentAccessGroupId = params.accessGroupId;
                                        _this.accessVmGroup = params.deviceList.map(item=>{
                                            let index =  _this.vmGroupData.findIndex((v)=>{
                                                return item.deviceId == v.key;
                                            });
                                            let labels_ = null;
                                            if(index!=-1){
                                                labels_ =  _this.vmGroupData[index].label
                                            }else{
                                                labels_ = item.deviceName
                                            }
                                            return {
                                                label:labels_,
                                                key:item.deviceId
                                            }
                                        })
                                    }
                                }
                            },'剔除')])
                        }
                    }
                ],
                userListData:[],
                userTransfer:false,
                vmGroupData:[],
                userGroupDataTargetData:[],
                userGroupDataTargetDataSelect:[],
                listStyle: {
                    width: '300px',
                    height: '400px'
                },
                userName:'',
                groupId:'',
                userId:'',
                accessVmGroup:[],
                userTransferDelete:false,
                userTransferDeleteLoading:true,
                tableHeight:200,
                currentSceneId:'',
                currentUserPartyValue:'',
                selectDeviceType:'vmDevice',
                currentUserData:[],
                accessDeviceGroup:[],
                accessVmsGroup:[],//用于切换设备类型进行回显
            }
        },
        
        created(){
            this.currentProjectId = this.$route.query.projectId
            this.currentSceneId = this.$route.query.testId
            this.getUserList()
            this.getVmList();
            // clearInterval(this.headerData.serintervalTimeFun)
        },
        methods:{
            getAccessDataMethods(userId,deviceId){
                let _this = this;
                axios({
                    url:'access/sessions?pageIndex=1&pageSize=10&projectId='+this.currentProjectId+'&userId='+userId+'&deviceId='+deviceId,
                }).then((response)=>{
                    if (response.code==1) {
                        _this.$refs.accessUserId.modal11 = true;
                        _this.$refs.accessUserId.accessDeatilObject = response.data.items[0];
                    }else{
                        this.$Message.error(response.message)
                    }
                })
            },
            getDeviceNameById(deviceId){
                let deviceName = null;
                let _this = this;
                for (let index = 0; index < _this.vmGroupData.length; index++) {
                    const element = _this.vmGroupData[index];
                    if(element.key==deviceId){
                        deviceName = element.label.split('--')[0]
                    }
                }
                return deviceName
            },
            accessVm(){
                let _this = this;
                let vmRecord = _this.switch1 ? true : false;
                if(_this.userGroupDataTargetData.length!=0){
                    return new Promise((reslove,reject)=>{
                        let idGroup = _this.userGroupDataTargetData.map((item)=>{
                            if (item&&item.charAt(0)=="V") {
                                return {
                                    deviceId:item,
                                    deviceType:"VM",
                                    enableRecordScreen:vmRecord,
                                    deviceName:_this.getDeviceNameById(item),
                                    enabled:_this.accessStart
                                }
                            } else {
                                return {
                                    deviceId:item,
                                    deviceType:"PM",
                                    enableRecordScreen:vmRecord,
                                    deviceName:_this.getDeviceNameById(item),
                                    enabled:_this.accessStart
                                }
                            }
                        });
                        reslove(idGroup)
                    }).then((value)=>{
                        axios({
                            url:'process/assign/devicesToUser',
                            method:'put',
                            data:{
                                "devices": value.concat(_this.accessDeviceGroup),
                                "testId": _this.currentSceneId,
                                "userId": _this.userId,
                                "accessGroupId":_this.currentAccessGroupId
                            }
                        }).then(function(response){
                            if(response.code==1){
                                _this.$Message.success("接入成功")
                                _this.userTransfer = false;
                                _this.getUserList()
                            }else{
                                _this.$Message.error(response.prompt)
                            }
                        })  
                    })
                }else{
                    _this.$Message.info("请选择要接入的虚拟机")
                }
                _this.userTransferLoading = false;
                _this.$nextTick(() => {
                    _this.userTransferLoading = true;
                });
            },
            cancel(){
                
            },
            getUserList(){
                let _this = this;
                axios({
                    url:'process/assign/userView?testId='+_this.currentSceneId,
                    method:'get',
                    params:{
                        pageIndex:_this.userCurrentPage,
                        pageSize:_this.usreItemPage
                    }
                }).then(function(response){
                    if(response.code==1){
                        _this.userListData =response.data.items;
                        _this.userTotal = response.data.total;
                    }else if(response.code==-2){
    
                    }else{
                        _this.$Message.error(response.prompt)
                    }
                })
            },
            getVmList(deviceList){
                let _this = this;
                _this.vmGroupData = []
                axios({
                    url:'topo-edit/vm/list/'+_this.currentProjectId,
                    method:'get',
                    params:{
                        page:1,
                        rows:100000,
                        sortBy:'name',
                        order:'asc',
                        party:_this.currentUserPartyValue,
                        findPorts:true
                    }
                }).then(function(response){
                    if(response.code==1){
                        let arr= [];
                        if(response.data.list&&response.data.list.length!=0){
                            for (let index = 0; index < response.data.list.length; index++) {
                                const item = response.data.list[index];
                                arr = [];
                                let IPs = [];
                                if(item.address){
                                    if(item.address.length!=0){
                                        item.address.map((item)=>{
                                            if(item.ips&&item.ips.length!=0){
                                                for(let i=0;i<item.ips.length;i++){
                                                    IPs.push(item.ips[i].ipAddress);
                                                }
                                            }
                                        })
                                        
                                    }
                                }
                                if(deviceList&&deviceList.length){
                                    for(let i=0;i<deviceList.length;i++){
                                        arr.push(deviceList[i].deviceId)
                                    }
                                    if(arr.indexOf(item.id)!=-1){
                                        _this.vmGroupData.push({
                                            label:item.networkName + '：' + item.name +'--'+ IPs.join(','),
                                            key:item.id,
                                            disabled:true
                                        })
                                    }else{
                                        _this.vmGroupData.push({
                                            label:item.networkName + '：' + item.name +'--'+ IPs.join(','),
                                            key:item.id,
                                            disabled:false
                                        })
                                    }
                                }else{
                                    _this.vmGroupData.push({
                                        label:item.networkName + '：' + item.name +'--'+ IPs.join(','),
                                        key:item.id,
                                        disabled:false
                                    })
                                }
                                
                            }
                        }
                    }else if(response.code==-2){
    
                    }else{
                        _this.$Message.error(response.prompt)
                    }
                })
            },
            getPhysicalList(deviceList){
                let _this = this;
                _this.vmGroupData = []
                axios({
                    url:'topo-edit/project/physicals',
                    method:'get',
                    params:{
                        page:1,
                        pageSize:10000,
                        sortBy:'name',
                        order:'asc',
                        projectId:_this.currentProjectId
                    }
                }).then((response)=>{
                    if (response.code==1) {
                        let arr= [];
                        if(response.data.list&&response.data.list.length!=0){
                            for (let index = 0; index < response.data.list.length; index++) {
                                const item = response.data.list[index];
                                let IPs = [];
                                arr = [];
                                if(item.addresses){
                                    IPs = item.addresses.map(ip=>{
                                        return ip.ipv4
                                    })
                                }
                                if(deviceList&&deviceList.length){
                                    for(let i=0;i<deviceList.length;i++){
                                        arr.push(deviceList[i].deviceId)
                                    }
                                    if(arr.indexOf(item.id)!=-1){
                                        _this.vmGroupData.push({
                                            label:'实物：'+item.name +'--'+ IPs.join(','),
                                            key:item.id,
                                            disabled:true
                                        })
                                    }else{
                                        _this.vmGroupData.push({
                                            label:'实物：'+item.name +'--'+ IPs.join(','),
                                            key:item.id,
                                            disabled:false
                                        })
                                    }
                                }else{
                                    _this.vmGroupData.push({
                                        label:'实物：'+item.name +'--'+ IPs.join(','),
                                        key:item.id,
                                        disabled:false
                                    })
                                }
                            }
                        }
                    }else if(response.code==-2){
    
                    } else {
                        this.$Message.error(response.message)
                    }
                })
            },
            getAttackDeviceList(deviceList){
                let _this = this;
                _this.vmGroupData = []
                axios({
                    url:'topo-edit/project/arms/'+this.currentProjectId+'/?hasDevices=true',
                }).then((response)=>{
                    if (response.code==1) {
                        let arr= [];
                        if(response.data.pageData&&response.data.pageData.length!=0){
                            for (let index = 0; index < response.data.pageData.length; index++) {
                                const item = response.data.pageData[index];
                               
                                arr = [];
                                for(let k=0;k<item.devices.length;k++){
                                    const items = item.devices[k];
                                    let IPs = [];
                                    if(items.ports){
                                        IPs = items.ports.map(ip=>{
                                            if(ip.ipv4){
                                                return ip.ipv4
                                            }else{
                                                return ip.ipv6
                                            }
                                        })
                                    }
                                    if(deviceList&&deviceList.length){
                                        for(let i=0;i<deviceList.length;i++){
                                            arr.push(deviceList[i].deviceId)
                                        }
                                        if(arr.indexOf(items.id)!=-1){
                                            _this.vmGroupData.push({
                                                label:item.toolName+'--'+items.name +'--'+ IPs.join(','),
                                                key:items.id,
                                                disabled:true
                                            })
                                        }else{
                                            _this.vmGroupData.push({
                                                label:item.toolName+'--'+items.name +'--'+ IPs.join(','),
                                                key:items.id,
                                                disabled:false
                                            })
                                        }
                                    }else{
                                        _this.vmGroupData.push({
                                            label:item.toolName+'--'+items.name +'--'+ IPs.join(','),
                                            key:items.id,
                                            disabled:false
                                        })
                                    }
                                }
                                
                            }
                        }
                    }else{
                        if(response.code!=-2){
                            this.$Message.error(response.message)
                        }   
                    }
                })
            },
            switchineUserCurrentPage(currPage){
                this.userCurrentPage = currPage
                this.getUserList()
            },
            switchUserItemPage(itemPage){
                this.usreItemPage = itemPage
                this.getUserList()
            },
            rednerItemUserData(item){
                return `<span title="${item.label}">${item.label}</span>`
            },
            listenChangeData(targetKeys,direction, moveKeys){
                this.userGroupDataTargetData = targetKeys;
            },
            switchVoid(value){
                this.switch1 = value
            },
            switchAccess(value){
                this.accessStart = value
            },
            getUserOfVm(userId){
                let _this = this;
                let arr = [];
                $.ajax({
                    url:'userjoin/instanceUserRelatione/getInstanceUserRelationePaginationList?page=1&rows=2000&userId='+userId+'&projectId='+_this.currentProjectId,
                    type:'get',
                    dataType: "json",
                    async:false,
                    contentType: "application/json",
                    headers:{"Authorization":localStorage.token},
                    success:(response)=>{
                        if(response.code == 1){
                            arr = response.attribute.dataList;
                        }else if(response.code==-2){
                        }else{
                            _this.$Message.error(response.prompt)
                        }
                    },
                    error:(response)=>{
                        _this.$Message.error(response.prompt)
                    }
                });
                return arr;
            },
            getDeviceFromUser(userId){
                let _this = this;
                let arr = [];
                $.ajax({
                    url:'access/records?page=1&rows=100000&userId='+userId+'&projectId='+_this.currentProjectId+'&status=connected',
                    type:'get',
                    dataType: "json",
                    async:false,
                    contentType: "application/json",
                    headers:{"Authorization":localStorage.token},
                    success:(response)=>{
                        if(response.code == 1){
                            arr = response.data.list;
                        }else if(response.code==-2){
                        }else{
                            _this.$Message.error(response.prompt)
                        }
                    },
                    error:(response)=>{
                        _this.$Message.error(response.prompt)
                    }
                });
                return arr;
            },
            deleteVmFromUser(currentUserId,vmGroup,vmId){
                let arr = [];
                let _this = this;
                for(let i=0;i<vmGroup.length;i++){
                    if(vmGroup[i].deviceId!=vmId){
                        arr.push(vmGroup[i])
                    }
                }
                axios({
                    url:'process/assign/devicesToUser',
                    method:'put',
                    data:{
                        "devices": arr,
                        "testId": _this.currentSceneId,
                        "userId": currentUserId,
                        "accessGroupId":_this.currentAccessGroupId
                    }
                }).then(function(response){
                    if(response.code==1){
                        _this.$Message.success('删除成功')
                        _this.userTransferDelete = false;
                        _this.getUserList();
                    }else{
                        _this.$Message.error(response.message)
                    }
                })
            },
            async deleteVmFromUserMany(){
                let _this = this;
                let arr = [];
                _this.currentUserData.forEach((element)=>{
                    if(_this.userGroupDataTargetData.indexOf(element.deviceId)==-1){
                        if (element.deviceId.charAt(0)=="V") {
                            arr.push({
                                deviceId:element.deviceId,
                                deviceType:"VM",
                                enableRecordScreen:element.enableRecordScreen,
                                deviceName:element.deviceName,
                            })
                        } else {
                            arr.push({
                                deviceId:element.deviceId,
                                deviceType:"PM",
                                enableRecordScreen:element.enableRecordScreen,
                                deviceName:element.deviceName,
                            })
                        }
                    }
                })
                await new Promise(resolve => {
                    axios({
                        url:'process/assign/devicesToUser',
                        method:'put',
                        data:{
                            "devices": arr,
                            "testId": _this.currentSceneId,
                            "userId": _this.userId,
                            "accessGroupId":_this.currentAccessGroupId
                        }
                    }).then(function(response){
                        if(response.code==1){
                            _this.userTransferDelete = false;
                            _this.getUserList();
                            resolve();
                        }else{
                            _this.$Message.error(response.message)
                        }
                    })
                });
            },
            deleteVm(){
                let _this = this;
                if(_this.userGroupDataTargetData.length!=0){
                    _this.deleteVmFromUserMany()
                }else{
                   _this.$Message.info("请选择要剔除的虚拟机")
                }
                 _this.userTransferDeleteLoading = false;
                _this.$nextTick(() => {
                    _this.userTransferDeleteLoading = true;
                });
            },
            reachTextLabel(data,query){
                return  data.label.toLowerCase().indexOf(query.toLowerCase()) > -1;
            },
            listenDeviceChange(value){
                if(value=="vmDevice"){
                    this.selectDeviceType = "vmDevice"
                    this.getVmList(this.accessVmsGroup);
                }else if(value=="pmDevice"){
                    this.selectDeviceType = "pmDevice"
                    this.getPhysicalList(this.accessVmsGroup);
                }else if(value=="atDevice"){
                    this.selectDeviceType = "atDevice"
                    this.getAttackDeviceList(this.accessVmsGroup);
                }
            }
        }
    }
</script>
    